package com.cruel_wandering.wifi_geo_predictor;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.DisplayMetrics;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyLocationOverlay extends Overlay {	
	private static final int pointRadius = 3;
	private static final float defaultAccuracy = 5;
	private float circleRadius ;
    private int lng;
    private int lat;
    private Paint pointPaint = new Paint();
    private Paint circlePaint = new Paint();
    private DisplayMetrics dm = new DisplayMetrics();
    @SuppressWarnings("unused")
    // for log
	private Context ctx;

    public MyLocationOverlay(int latSrc, int lngSrc,float accuracy, DisplayMetrics dmSrc, Context ctxSrc) {
    	lat = latSrc;
    	lng = lngSrc;
    	if(accuracy == 0)
    		accuracy = defaultAccuracy;
    	circleRadius = accuracy;
    	pointPaint.setARGB(225, 0, 50, 255);
    	circlePaint.setARGB(30, 0, 150, 255);
        dm.setTo(dmSrc);
        ctx = ctxSrc;
    }

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {	
		Projection projection = mapView.getProjection();
		Point point = new Point();
		projection.toPixels(new GeoPoint(lat, lng), point );
		double zoom = MapScreen.maxZoom - mapView.getZoomLevel();
		int r = (int) ((circleRadius * dm.widthPixels) /
				(MapScreen.minSpan * Math.pow(MapScreen.zoomCoeff, zoom)));
		canvas.drawCircle(point.x, point.y, pointRadius, pointPaint);
		canvas.drawCircle(point.x, point.y, r, circlePaint);	
		super.draw(canvas, mapView, shadow);
	}  
}